import { _decorator, Color, Component, Label, Node, Vec3 } from 'cc';
import { Core } from '../core/Core';
import { EprefabName } from '../core/Config';
import { Context } from './Context';
const { ccclass, property } = _decorator;

@ccclass('NumberText')
export class NumberText extends Component {

    label: Label;

    protected onLoad(): void {
        this.label = this.node.getComponent(Label);
    }

    start() {

    }

    update(deltaTime: number) {

    }

    static show(text: string, worldPosition: Vec3, color: Color = Color.WHITE, duration: number = 1) {
        let node = Core.instance.creatNode(EprefabName.NUMBER_TEXT, Context.texts);
        node.setWorldPosition(worldPosition);
        let numberText = node.getComponent(NumberText);
        numberText.label.color = color;
        numberText.label.string = text;
        numberText.scheduleOnce(() => node.destroy(), duration)

    }
}


